home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / toolbox / rot90 < prev    next >
Text File  |  1994-06-26  |  979b  |  48 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. // Synopsis:    Rotate a matrix by 90 degrees.
  4.  
  5. // Syntax:    rot90 ( A )
  6. //        rot90 ( A , K )
  7.  
  8. // Description:
  9.  
  10. //    If K is omitted, then A (M x N) is rotated by 90
  11. //    degrees. Otherwise, A is rotated by K*90 degrees. K can take
  12. //    on positive or negative values. 
  13.  
  14. //    rot90 is useful with plmesh() and plot3d(). Using rot90, the
  15. //    user can rotate the surface by 90 degrees in either direction.
  16.  
  17. //-------------------------------------------------------------------//
  18.  
  19. rot90 = function ( A , k )
  20. {
  21.   local (k, B, m, n)
  22.  
  23.   m = A.nr; n = A.nc;
  24.   if (!exist (k)) 
  25.   {
  26.     k = 1;         // default
  27.   else
  28.     k = mod(k,4);    // take out 360 deg. rotations
  29.     if (k < 0)
  30.     {
  31.       k = k + 4;    // Force positve
  32.     }
  33.   }
  34.  
  35.   if (k == 1)
  36.   {
  37.     B = A'[n:1:-1;];        // 90
  38.   else if (k == 2) {
  39.     B = A[m:1:-1;n:1:-1];    // 180
  40.   else if (k == 3) {
  41.     B = (A[m:1:-1;])';        // 270
  42.   else
  43.     B = A;            // 360
  44.   }}}
  45.  
  46.   return B;
  47. };
  48.